package org.farm2.ai.test.client;

import com.alibaba.cloud.ai.dashscope.api.DashScopeAudioTranscriptionApi;
import com.alibaba.cloud.ai.dashscope.audio.DashScopeAudioTranscriptionModel;
import com.alibaba.cloud.ai.dashscope.audio.DashScopeAudioTranscriptionOptions;
import org.farm2.ai.test.config.ApiConfig;
import org.springframework.ai.audio.transcription.AudioTranscriptionPrompt;
import org.springframework.ai.audio.transcription.AudioTranscriptionResponse;
import org.springframework.core.io.UrlResource;

import java.net.MalformedURLException;

public class AudioDemo {
    public static void main(String[] args) throws MalformedURLException {
        getClient();
    }

    private static final String AUDIO_RESOURCES_URL = "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav";


    public static void getClient() throws MalformedURLException {
        String apiKey = ApiConfig.apiKey;
        DashScopeAudioTranscriptionApi dashScopeApi = new DashScopeAudioTranscriptionApi(apiKey);
        DashScopeAudioTranscriptionModel model = new DashScopeAudioTranscriptionModel(dashScopeApi);

        // 音频资源
        UrlResource audioResource = new UrlResource(AUDIO_RESOURCES_URL);

        // 指定参数
        DashScopeAudioTranscriptionOptions transcriptionOptions = DashScopeAudioTranscriptionOptions.builder()
                .withModel("sensevoice-v1")
                .build();

        AudioTranscriptionResponse response = model.call(
                new AudioTranscriptionPrompt(audioResource, transcriptionOptions)
        );
        System.out.println(response.getResult().getOutput());

    }


}
